
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import { close, start } from '@/utils/nporgress'



const Login = () => import("@/views/login/login.vue");
const Main = () => import("@/views/main/main.vue");
const Home = () => import("@/views/home/Home.vue");


const routes = [
  {
    path: "/",
    redirect: '/login'
  },
  {
    path: '/login',
    name: "login",
    component: Login
  },
  {
    path: "/main",
    component: Main,
    name: '首页',
    redirect: '/home',//默认让router-view显示页面
    // 有两个router-view时必须要childrn，才能显示
    children: [
      // 第一级菜单
      {
        path: "/home",
        name: "首页",
        children: [],
        component: Home
      },
      {
        name: "文章管理",
        path: "/article-submenu",
        // 第二级菜单
        children: [
          {
            name: "发布文章",
            path: "/articles",
            component: () => import("@/views/article/Article.vue"),
          },
          {
            name: "文章列表",
            path: "/article-list",
            component: () => import("@/views/article/ArticleList.vue"),
          }
        ]
      },
    ]
  }


]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

/**
 * 进度条切换配置
 */

router.beforeEach((pre, next) => {
  start() //开始进度条
})

//afterEach路由切换之后触发

router.afterEach(() => {
  close() //结束进度条
})
export default router;